﻿using Maticsoft.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AppCash
{
    public partial class frmJB : Form
    {
        int banci = ZhiKeDuoServer.Model.GlobalsInfo.banci;
        public frmJB()
        {
            InitializeComponent();
        }



        private void buttonX1_Click(object sender, EventArgs e)
        {
            PrintOrder(dGV);
            System.IO.File.WriteAllText(System.Environment.CurrentDirectory + "/banci", (banci+1).ToString());
            
        }
        public void PrintOrder(DataGridView dgv)
        {

            if (dgv.Rows.Count > 0)
            {

                BeiYangOPOS opos = new BeiYangOPOS();

                bool b = opos.OpenPrinter(ZhiKeDuoServer.Model.GlobalsInfo.PrinterIPAddress);
                if (!b)
                {
                    LogManager.WriteLog("Error",
                        "初始化的打印机参数失败。请检测打印机配置。");
                }
                else
                {
                    BeiYangOPOS.POS_StartDoc();
                    //ZhiKeDuoServer.Model.GlobalsInfo.Shop.Name
                    BeiYangOPOS.POS_SetRightSpacing(0);
                    BeiYangOPOS.POS_SetLineSpacing(100);
                    BeiYangOPOS.POS_S_TextOut("收银交班表", 50, 2, 2, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);
                    BeiYangOPOS.POS_FeedLines(1);
                    BeiYangOPOS.POS_SetLineSpacing(24);
                    BeiYangOPOS.POS_S_TextOut("付款方式", 5, 1, 1, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);
                    BeiYangOPOS.POS_S_TextOut("金额", 200, 1, 1, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);

                    BeiYangOPOS.POS_FeedLines(1);
                    BeiYangOPOS.POS_S_TextOut("--------------------------------", 0, 1, 1, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);
                    BeiYangOPOS.POS_FeedLines(1);

                }



                for (int i = 0; i < dgv.Rows.Count; i++)
                {


                    BeiYangOPOS.POS_S_TextOut(dgv.Rows[i].Cells[1].Value.ToString(), 10, 1, 1, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);
                    BeiYangOPOS.POS_S_TextOut(dgv.Rows[i].Cells[0].Value.ToString(), 200, 1, 1, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);
                    BeiYangOPOS.POS_FeedLines(1);
                    BeiYangOPOS.POS_S_TextOut("--------------------------------", 0, 1, 1, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);
                    BeiYangOPOS.POS_FeedLines(1);

                }

         

                //BeiYangOPOS.POS_S_TextOut("总计:" + tbYS.Text, 200, 1, 1, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_TYPE_CHINESE);
                BeiYangOPOS.POS_FeedLines(5);
                BeiYangOPOS.POS_CutPaper(0, 200);

                BeiYangOPOS.POS_KickOutDrawer(0x00, 10, 10);
                //BeiYangOPOS.POS_KickOutDrawer(0x01, 50, 50);
                BeiYangOPOS.POS_EndDoc();
                BeiYangOPOS.POS_Close();
            }
        }


        private void frmJB_Load(object sender, EventArgs e)
        {
            ZhiKeDuoServer.BLL.SaleInfo saleInfo = new ZhiKeDuoServer.BLL.SaleInfo();
            double jine = 0;
           DataTable ds=  saleInfo.Jiaoban(banci,ZhiKeDuoServer.Model.GlobalsInfo.Shop.Shop, ZhiKeDuoServer.Model.GlobalsInfo.UserName);
            foreach (DataRow item in ds.Rows)
            {
                jine = jine + (double)item["money"];
            }

            ds.Rows.Add(string.Format("{0:F2}", jine) , "总计") ;
     
           
            dGV.DataSource = ds;

        }


    }
}
